<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<!-- .breadcrumb -->
	</div>
	<div class="page-content">
        
        <div class="page-header">
			<h1>追加优惠卷</h1>
		</div>
		<div class="row">
			 <div class="col-xs-12">
				<!-- PAGE CONTENT BEGINS -->

					<form id="usrform" action="<?php echo base_url()."admin/activity/add_discount_coupon/".$id?>" method="post">
				    	<div class="box-body" style="display: inline-block;width: 100%" id="content">
				    		<?php
				    			if(isset($discount_coupon)&&count($discount_coupon)>0){
				    				foreach($discount_coupon as $dis_val){	
				    		?>
				    			<div>
						            <div class="form-group col-xs-6">
							            <label>选择优惠卷</label><span style="color: #a94442;"><?php echo form_error("complain[]")?></span>
							            <select name="complain[]" class="form-control" check-type="required">
							            	<?php
							            		foreach($result as $val){
							            	?>
				                            	<option value="<?php echo $val->id ?>" <?php if ($dis_val->coupon_id == $val->id)echo "selected";?>><?php echo $val->coupon_name ?></option>
				                            <?php
				                            	}	
				                            ?>
						                </select>
						            </div>
						            <div class="form-group col-xs-4">
							            <label>数量</label><span style="color: #a94442;"><?php echo form_error("count[]")?></span>
							            <input type="text" class="form-control" name="count[]" check-type="required"  value="<?php echo $dis_val->count; ?>" />
						            </div>
						            <div class="form-group col-xs-2">
						            	<button class="btn btn-pink" type="button" style="margin-top: 19px;" onclick="del(this)">
											<i class="icon-ok bigger-110"></i>
											删除
										</button>
						            </div>
					            </div>
				    		<?php
								}
								}else{	
				    		?>
				    		<div>
					            <div class="form-group col-xs-6">
						            <label>选择优惠卷</label><span style="color: #a94442;"><?php echo form_error("complain[]")?></span>
						            <select name="complain[]" class="form-control" check-type="required">
						            	<?php
						            		foreach($result as $val){
						            	?>
			                            	<option value="<?php echo $val->id ?>"><?php echo $val->coupon_name ?></option>
			                            <?php
			                            	}	
			                            ?>
					                </select>
					            </div>
					            <div class="form-group col-xs-4">
						            <label>数量</label><span style="color: #a94442;"><?php echo form_error("count[]")?></span>
						            <input type="text" class="form-control" name="count[]" check-type="required"  value="<?php echo set_value("count[]")?>" />
					            </div>
					            <div class="form-group col-xs-2">
					            	<button class="btn btn-pink" type="button" style="margin-top: 19px;" onclick="del(this)">
										<i class="icon-ok bigger-110"></i>
										删除
									</button>
					            </div>
				            </div>
				            <?php 
				            	}	
				            ?>
			            </div>
			            <div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button id="btnSubmit" class="btn btn-info" type="submit">
									<i class="icon-ok bigger-110"></i>
									保存
								</button>
	
								&nbsp; &nbsp; &nbsp;
								<a class="btn" href="<?php echo base_url()."admin/activity/discount"?>">
									<i class="icon-undo bigger-110"></i>
									返回
								</a>
								&nbsp; &nbsp; &nbsp;
								<button id="btn1" type="button" class="btn btn-warning">添加优惠卷</button>
							</div>
						</div>
					</form>
			</div>
		</div><!-- /.row -->
	</div><!-- /.page-content -->
</div><!-- /.main-content -->
<script type="text/javascript">
$("#usrform").validation();
//保存
$("#btnSubmit").on('click',function(event){
  // 2.最后要调用 valid()方法。
  if ($("#usrform").valid()==false){
    return false;
  }
});
</script>
<script>
	//删除
		function del(e){
			//confirm()方法用于显示一个带有指定消息和 OK 及取消按钮的对话框,括号里是可以追加你要提示的相关内容的
			if(confirm("确定删除此站点？")){
				$(e).parent().parent().remove();
			}
		}
</script>
<script>
	$(document).ready(function(){
		  $("#btn1").click(function(){
		    $("#content").append('<div><div class="form-group col-xs-6"><label>选择优惠卷</label><span style="color: #a94442;"><?php echo form_error("complain[]")?></span><select name="complain[]" class="form-control" check-type="required"><?php foreach($result as $val){ ?> <option value="<?php echo $val->id ?>"><?php echo $val->coupon_name ?></option><?php } ?></select></div><div class="form-group col-xs-4"><label>数量</label><span style="color: #a94442;"><?php echo form_error("count[]")?></span><input type="text" class="form-control" name="count[]" check-type="required"  value="<?php echo set_value("count[]")?>" /></div><div class="form-group col-xs-2"><button class="btn btn-pink" type="button" style="margin-top: 19px;" onclick="del(this)"><i class="icon-ok bigger-110"></i>删除</button></div></div>');
		  });
	});
</script>